package com.brandonflowers.hiveswfaddressdemo.states
{
	import com.brandonflowers.hiveswfaddressdemo.data.HiveDemoData;
	import flash.display.Shape;
	
	import org.hive.managers.plugin.LayoutManager;
	import org.hive.managers.StateManager;
	import org.hive.state.*;
	import org.hive.sequence.*;
	
	import com.brandonflowers.hiveswfaddressdemo.states.*;
	import flash.text.*;
	import flash.display.Sprite;
	
	public class HomeState extends State implements IState
	{
		private var homeBG	:Shape;
		private var homeTXT :TextField;
		private var homeContainer:Sprite;
		
		public override function create():ActionSequence
		{
			//________________________________________________________________________ ASSETS
			homeBG = new Shape();
			homeBG.graphics.beginFill(0xff2200);
			homeBG.graphics.drawRect(0, 0, 400, 300);
			homeBG.x = 0;
			homeBG.y = 0;
						
			homeTXT = new TextField();
			
			var format:TextFormat = new TextFormat();
			format.color = 0xff2200;
			format.size = 30;
			format.bold = true;
			format.font = "Helvetica";
			
			homeTXT = new TextField();
			homeTXT.embedFonts = true;
			homeTXT.autoSize = TextFieldAutoSize.LEFT;
			homeTXT.antiAliasType = AntiAliasType.ADVANCED;
			homeTXT.defaultTextFormat = format;
			homeTXT.selectable = false;
			homeTXT.mouseEnabled = false;
			
			homeTXT.text = "HOME";
			
			homeTXT.x = homeBG.x;
			homeTXT.y = homeBG.y + homeBG.height + 10;
			
			homeContainer = new Sprite();
						
			homeContainer.addChild(homeBG);
			homeContainer.addChild(homeTXT);
			
			homeContainer.alpha = 0;
			
			homeContainer.x = 40;
			homeContainer.y = 40;
						
			//________________________________________________________________________ SEQUENCE
			var createSequence:ActionSequence = new ActionSequence( "HomeState::createSequence" );
			createSequence.push( { scope:homeContainer, alpha:1, time:1, transition:"easeoutsine" } );
			createSequence.push( new SequenceDelay(1000) );
			createSequence.push( { scope:homeContainer, x:300, time:2, transition:"easeoutback" } );
			createSequence.push( new SequenceDelay(2000) );
			
			
			return createSequence;
		}

		private function kill():void
		{
			LayoutManager.removeChild( homeContainer );
		}
		
		public override function close():CloseSequence
		{
			var closeSequence:CloseSequence = new CloseSequence( "HomeState::closeSequence" );
			
			closeSequence.push( {scope:homeContainer, alpha:0, y:homeContainer.y + 300, time:1} );
			closeSequence.push( new SequenceDelay(1000) );
			closeSequence.push( new SequenceFunction(this, kill) );
			
			return closeSequence;
		}
		
	}
	
}
